﻿using System.Collections.Generic;
using System.Xml.Linq;
using Harvest.API.Model;

namespace Harvest.API
{

    public partial class Wrapper
    {

        /// <summary>
        /// Get all clients.
        /// </summary>
        /// <remarks>GET /clients</remarks>
        /// <returns></returns>
        public List<Client> GetClients()
        {
            var data = Request(WebRequestMethodEnum.Get, "clients");
            var xDocument = XDocument.Parse(data);
            return xDocument.ToClients();
        }

        /// <summary>
        /// Get an existing client.
        /// </summary>
        /// <remarks>GET /clients/#{client_id}</remarks>
        /// <param name="id"></param>
        /// <returns></returns>
        public Client GetClient(int id)
        {
            var data = Request(WebRequestMethodEnum.Get, "clients/" + id);
            var xDocument = XDocument.Parse(data);
            return xDocument.ToClient();
        }

        /// <summary>
        /// Delete an existing client.
        /// </summary>
        /// <remarks>DELETE /clients/#{client_id}</remarks>
        /// <param name="id"></param>
        /// <returns></returns>
        public string DeleteClient(int id)
        {
            var data = Request(WebRequestMethodEnum.Delete, "clients/" + id);
            return data;
        }

        /// <summary>
        /// Activate or deactivate an existing client.
        /// </summary>
        /// <remarks>PUT /clients/#{client_id}/toggle</remarks>
        /// <param name="id"></param>
        /// <returns></returns>
        public string ToggleClientActive(int id)
        {
            var data = Request(WebRequestMethodEnum.Put, "clients/" + id + "/toggle");
            return data;
        }

        /// <summary>
        /// Update an existing client.
        /// </summary>
        /// <remarks>PUT /clients/#{client_id}</remarks>
        /// <param name="client"></param>
        /// <returns></returns>
        public string UpdateClient(Client client)
        {
            var data = Request(WebRequestMethodEnum.Put, "clients/" + client.Id, client.Serialize());
            return data;
        }

        /// <summary>
        /// Create a new client.
        /// </summary>
        /// <remarks>POST /clients</remarks>
        /// <param name="client"></param>
        /// <returns></returns>
        public string CreateClient(Client client)
        {
            var data = Request(WebRequestMethodEnum.Post, "clients", client.Serialize());
            return data;
        }

    }

}
